﻿using Lanbt.Core.Entity.Dto;
using Lanbt.Core.Entity.Dto.lanbt_system_config;
using Lanbt.Core.Entity.Enums;
using Lanbt.Core.Service.SqlService.IService;
using Lanbt.Core.Utility;
using Lanbt.Core.Web.Controllers.Base;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.ComponentModel.DataAnnotations;

namespace Lanbt.Core.Web.Controllers.Action
{
    public class ConfigAction : ActionController
    {
        private readonly IConfigService _configService;
        public ConfigAction(IConfigService systemConfigService)
        {
            _configService = systemConfigService;
        }

        /// <summary>
        /// 获取系统配置信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet("/lanbt.system.config.get")]
        public async Task<ResultOutput> GetSystemConfig([Required][Range(1, int.MaxValue)] SystemConfigKey key)
        {
            return await _configService.GetSystemConfig(key);
        }

        /// <summary>
        /// 获取用户配置信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet("/lanbt.user.config.get")]
        public async Task<ResultOutput> GetUserConfig([Required][Range(1, int.MaxValue)] UserConfigKey key)
        {
            return await _configService.GetUserConfig(key);
        }

        /// <summary>
        /// 添加系统配置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/lanbt.config.operation")]
        public async Task<ResultOutput> OperationConfig([FromBody] ConfigInputDto input)
        {
            return await _configService.OperationConfig(input);
        }

        /// <summary>
        /// 删除系统配置
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpDelete("/lanbt.system.config.delete")]
        public async Task<ResultOutput> DeleteSystemConfig([Required][Range(1,int.MaxValue)] SystemConfigKey key)
        {
            return await _configService.DeleteSystemConfig(key);
        }

        /// <summary>
        /// 删除用户配置
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpDelete("/lanbt.user.config.delete")]
        public async Task<ResultOutput> DeleteUserConfig([Required][Range(1, int.MaxValue)] UserConfigKey key)
        {
            return await _configService.DeleteUserConfig(key);
        }
    }
}
